package com.sakhalin.news.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import com.sakhalin.news.viewmodels.datasource.NewsListDataSource

class NewsListViewModel(private val newsCategory: String) : BaseViewModel() {

    class Factory(private val newsCategory: String) : ViewModelProvider.Factory {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            return NewsListViewModel(newsCategory) as T
        }
    }

    val newsList = Pager(PagingConfig(
        pageSize = 10,
        prefetchDistance = 10)
    ) { NewsListDataSource(newsCategory)  }.flow.cachedIn(viewModelScope)
}